package jf.jplayground.validation;
import java.util.Arrays;
import java.util.Set;
import java.util.logging.Logger;

import javax.validation.ConstraintViolation;
import javax.validation.Validation;
import javax.validation.Validator;
import javax.validation.ValidatorFactory;

public class BeanValidator {

	private static Logger LOGGER = Logger.getLogger(BeanValidator.class.getName());

	public static void main(String[] args) {

		BeanToValidate bean = new BeanToValidate();

		bean.setAge(29);
		bean.setEmail("doesnotexist@martinmaier.name");
		bean.setName("Martin Maier");
		bean.setThings(Arrays.asList("A", "B", "C"));

		
		ValidatorFactory factory = Validation.buildDefaultValidatorFactory();

		Validator validator = factory.getValidator();

		Set<ConstraintViolation<BeanToValidate>> violations = validator.validate(bean);
		
		for (ConstraintViolation<BeanToValidate> violation : violations) {
			LOGGER.severe(violation.getPropertyPath().toString() + " " + violation.getMessage());
		}
	}
}
